package com.inspur.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.inspur.system.service.IPmDynService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.inspur.common.annotation.Log;
import com.inspur.common.core.controller.BaseController;
import com.inspur.common.core.domain.AjaxResult;
import com.inspur.common.enums.BusinessType;
import com.inspur.system.domain.PmDyn;
import com.inspur.common.utils.poi.ExcelUtil;
import com.inspur.common.core.page.TableDataInfo;

/**
 * 动态Controller
 * 
 * @author lihaodong
 * @date 2024-04-10
 */
@RestController
@RequestMapping("/system/dyn")
public class PmDynController extends BaseController
{
    @Autowired
    private IPmDynService pmDynService;

    /**
     * 查询动态列表
     */
    @PreAuthorize("@ss.hasPermi('system:dyn:list')")
    @GetMapping("/list")
    public TableDataInfo list(PmDyn pmDyn)
    {
        startPage();
        List<PmDyn> list = pmDynService.selectPmDynList(pmDyn);
        return getDataTable(list);
    }

    /**
     * 导出动态列表
     */
    @PreAuthorize("@ss.hasPermi('system:dyn:export')")
    @Log(title = "动态", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PmDyn pmDyn)
    {
        List<PmDyn> list = pmDynService.selectPmDynList(pmDyn);
        ExcelUtil<PmDyn> util = new ExcelUtil<PmDyn>(PmDyn.class);
        util.exportExcel(response, list, "动态数据");
    }

    /**
     * 获取动态详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:dyn:query')")
    @GetMapping(value = "/{cDynNo}")
    public AjaxResult getInfo(@PathVariable("cDynNo") Long cDynNo)
    {
        return success(pmDynService.selectPmDynByCDynNo(cDynNo));
    }

    /**
     * 获取动态详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:dyn:listpm')")
    @GetMapping(value = "/pm")
    public AjaxResult getInfo(PmDyn pmDyn)
    {
        return success(pmDynService.selectPmDynByCPmNo(pmDyn));
    }

    /**
     * 新增动态
     */
    @PreAuthorize("@ss.hasPermi('system:dyn:add')")
    @Log(title = "新增动态", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PmDyn pmDyn)
    {
        pmDyn.setcDynType("2");
        return toAjax(pmDynService.insertPmDyn(pmDyn));
    }

    /**
     * 修改动态
     */
    @PreAuthorize("@ss.hasPermi('system:dyn:edit')")
    @Log(title = "动态", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PmDyn pmDyn)
    {
        return toAjax(pmDynService.updatePmDyn(pmDyn));
    }

    /**
     * 删除动态
     */
    @PreAuthorize("@ss.hasPermi('system:dyn:remove')")
    @Log(title = "动态", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cDynNos}")
    public AjaxResult remove(@PathVariable Long[] cDynNos)
    {
        return toAjax(pmDynService.deletePmDynByCDynNos(cDynNos));
    }

    /**
     * 查询动态数量
     */
    @PreAuthorize("@ss.hasPermi('system:dyn:listnum')")
    @GetMapping("/listNum/{cPmNo}")
    public AjaxResult listNum(@PathVariable("cPmNo") String cPmNo)
    {
        return success(pmDynService.selectPmDynNum(cPmNo));
    }
}
